import { ConsoleMessage } from "puppeteer";
import { logger } from '../../utils/web-logger.util'
export const ConsoleHandler: (e: ConsoleMessage, ...args: any[]) => void = (e, args) => {
  let message = `console from puppeteer: ${e.text()}`;
  const argus = e.args();
  if (args) {
    message += JSON.stringify(argus.map(a => a.jsonValue()));
  }
  switch (e.type()) {
    case 'debug':
      logger.debug(message);
      break;
    case 'warning':
      logger.warn(message);
      break;
    case 'error':
      logger.warn(message);
      break;
    case 'info':
      logger.info(message);
    default:
      logger.debug(message);
  }
}